//
//  LianXiKeFuController.m
//  PosApp
//
//  Created by 刘萍 on 2018/9/13.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "LianXiKeFuController.h"
#import "LianXiKeFuModel.h"

@interface LianXiKeFuController ()
@property (weak, nonatomic) IBOutlet UIImageView *LianXiImage;
@property (weak, nonatomic) IBOutlet UILabel *LianXiLabel01;
@property (weak, nonatomic) IBOutlet UILabel *LianXiLabel02;


@property (strong, nonatomic) LianXiKeFuModel * model;

@end

@implementation LianXiKeFuController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationItem.title = @"客服中心";
    
    self.LianXiImage.userInteractionEnabled = YES;
    UITapGestureRecognizer * ImageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickOnImageOfLianXiImage)];
    [self.LianXiImage addGestureRecognizer:ImageTap];
    
    [self UpLoadDataOfLianXiKeFuController];
}

- (void)UpLoadDataOfLianXiKeFuController{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];
    [dic setObject:KUseriPhone forKey:@"phone"];
    
    [MainObjectWay PostWithMethod:@"contact" andAction:@"User" andAddParam:YES parameters:dic success:^(id responseObject) {
        NSLog(@"返回的数据 = %@",responseObject);
        if ([MainObjectWay IsSucceedWithCode:responseObject[@"code"]]) {
            NSMutableDictionary * dic = responseObject[@"data"];
            self.model = [LianXiKeFuModel mj_objectWithKeyValues:dic];
            [self.LianXiImage sd_setImageWithURL:[NSURL URLWithString:self.model.site_pic] placeholderImage:[UIImage imageNamed:@"MainZWImage"]];
            self.LianXiLabel01.text = [NSString stringWithFormat:@"%@",self.model.site_tel];
            self.LianXiLabel02.text = [NSString stringWithFormat:@"%@",self.model.site_phone];
        }
    } failure:^(NSError *error) {
        NSLog(@"错误信息 = %@",error);
    }];
}
- (void)ClickOnImageOfLianXiImage{
    CIDetector*detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:nil options:@{ CIDetectorAccuracy : CIDetectorAccuracyHigh }];
    
    UIImage * image = [UIImage imageNamed:@"LianXiImage01"];
    
    CGImageRef ref = image.CGImage;
    
    //2. 扫描获取的特征组
    
    NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:ref]];
    
    //3. 获取扫描结果
    
    CIQRCodeFeature *feature = [features objectAtIndex:0];
    
    NSString *scannedResult = feature.messageString;
    
    NSLog(@"=====%@",scannedResult);
    
}
- (IBAction)ClickOnBtnToLianXi01:(id)sender {
    
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.model.site_tel]];
    //调用系统方法拨号
    [[UIApplication sharedApplication] openURL:url];
}


- (IBAction)ClickOnBtnToLianXi02:(id)sender {
    
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.model.site_phone]];
    //调用系统方法拨号
    [[UIApplication sharedApplication] openURL:url];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
